﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.OpenRoboticMachineDataFolder.CApOpenRoboticMachineDataFolderCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.OpenRoboticMachineDataFolder;

public class CApOpenRoboticMachineDataFolderCmd : TxButtonCommand
{
  protected CApOpenRoboticMachineDataFolderEnabler m_enabler;

  public CApOpenRoboticMachineDataFolderCmd()
  {
    this.m_enabler = new CApOpenRoboticMachineDataFolderEnabler();
  }

  public virtual string Category => DnProcessSimulateCommands.OpenRoboticMachineDataFolder.OpenRoboticMachineDataFolder.CMD_CATEGORY;

  public virtual string Name => DnProcessSimulateCommands.OpenRoboticMachineDataFolder.OpenRoboticMachineDataFolder.CMD_NAME;

  public virtual string Tooltip => DnProcessSimulateCommands.OpenRoboticMachineDataFolder.OpenRoboticMachineDataFolder.CMD_TOOLTIP;

  public virtual string Bitmap
  {
    get => "OpenRoboticMachineDataFolder.Open_Robot-Machine_Data_Folder_16.bmp";
  }

  public virtual string MediumBitmap
  {
    get => "OpenRoboticMachineDataFolder.Open_Robot-Machine_Data_Folder_24.png";
  }

  public virtual string LargeBitmap
  {
    get => "OpenRoboticMachineDataFolder.Open_Robot-Machine_Data_Folder_32.png";
  }

  public virtual string Description => DnProcessSimulateCommands.OpenRoboticMachineDataFolder.OpenRoboticMachineDataFolder.CMD_DESCRIPTION;

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Licensed => TxCommandLicenser.OpenRoboticMachineDataFolderLicense;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("OpenMachineDataFolder");

  public virtual void Execute(object cmdParams)
  {
    foreach (ITxObject itxObject in (Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())
    {
      TxRobot robot = itxObject as TxRobot;
      Process.Start(this.SystemFilesPrivateFolder(robot));
      robot.SetDataInPathAsModified();
    }
  }

  public string SystemFilesPrivateFolder(TxRobot robot)
  {
    string path = this.RrsRobotPathName(robot);
    if (path == null)
      return (string) null;
    if (!Directory.Exists(path))
      Directory.CreateDirectory(path);
    return path;
  }

  public string RrsRobotPathName(TxRobot robot)
  {
    string input = this.RobotPathName(robot);
    if (input == null)
      return (string) null;
    Match match = new Regex("^(\\w:\\\\|\\\\\\\\)\\\\*(.*)$").Match(input);
    if (match != null && match.Success)
      input = match.Groups[1]?.ToString() + match.Groups[2].ToString().Replace("\\\\", "\\");
    return input;
  }

  internal string RobotPathName(TxRobot robot)
  {
    string pathName = robot.ComputePathName();
    if (!Directory.Exists(pathName))
      Directory.CreateDirectory(pathName);
    return pathName;
  }
}
